package classesdemo;

/**
 * Created by pc on 2015/2/11.
 * 让每个枚举类实例有不同的成员变量，可以在构造器中指定
 * 若想让各个实例实现接口时有不同的实现，可以像匿名内部类一样，
 * 在定义时指定* *
 */
interface Desc{
    String info();
}
enum JobStatus implements Desc{
    QUEUED{
        public String info() {
            return "等待中"; 
        } 
    }, 
    RUNNING{
        public String info(){
            return "运行中"; 
        }
        
    }, HALTED{
        public String info(){
            return "出错了"; 
        }
        
    }, CAN_CONTINUE{
        public String info(){
            return "可以继续";
        }
    };
    private String desc;

//    JobStatus(){
//    public void setDesc(){
//        switch (this) { //this can't be used in constructor?
//            case QUEUED:
//                desc = "waiting to be called..";
//                break;
//            case RUNNING:
//                desc = "working..";
//                break;
//            case HALTED:
//                desc = "error happened..";
//                break;
//            case CAN_CONTINUE:
//                desc = "resumed..";
//                break;
//            default:
//                desc = "SHOULDN'T HAPPEN!!";
//        }
//    }
//    public String info() {
//        return desc;
//    }
}

public class EnumDemo {
    public static void main(String args[]) {
//        System.out.println("can_conintue index: " + JobStatus.CAN_CONTINUE.ordinal());
//        System.out.println("running name is: " + JobStatus.RUNNING.name());
//        System.out.println("queued value of: " + JobStatus.valueOf("QUEUED"));
//        JobStatus.RUNNING.setDesc();
        for(JobStatus js: JobStatus.values()){
            System.out.println("js name: " + js.toString() + ", desc: " + js.info());
        }

    }

}

